/**
 * Created by leiweibo on 6/28/15.
 */

var app = angular.module('materialservice', []);
app.factory('MaterialService', function($http, BaseService) {
  function getPage(pageNo, pageSize, params, success) {

    var filterCondition = params.search.predicateObject;
    var queryStr = '';
    if (filterCondition) {
      if (filterCondition.username) {
        queryStr += ('&username=' + filterCondition.username);
      }

      if (filterCondition.realname) {
        queryStr += ('&realname=' + filterCondition.realname);
      }
    }
    $http.get(BaseService.baseUrl + "/material/list?pageNo=" + pageNo + "&pageSize=" + pageSize)
      .success(success);
  }


  return {
    list: getPage,
    create: function(data, success, error) {
      $http.post(BaseService.baseUrl + '/material/create', data).success(success).error(error);
    },
    update: function(data, success, error) {
      $http.put(BaseService.baseUrl + '/material/update', data).success(success).error(error);
    },
    delete: function(data, success, error) {
      $http.delete(BaseService.baseUrl + '/material/delete?id=' + data.id).success(success).error(error);
    },
    getDetail: function(data, success, err) {
      $http.get(BaseService.baseUrl + "/material/dtl?id=" + data).success(success);
    }
  }
}).factory('MaterialData', function() {
  var savedData = {};
  function set(data) {
    savedData = data;
  }

  function get() {
    return savedData
  }

  return {
    get: get,
    set: set
  }

});
